#!/usr/bin/env python
# encoding: utf-8
"""
latticeXMLFunctions.py

Created by Pablo Ortega Mesa on 2011-01-28.
Copyright (c) 2011 Toeska Research Group. All rights reserved.
"""
from xml.dom import minidom

def getAttrObj(xmlFile):
	attrs = {}
	objs = {}
	flagA=False
	flagO=False
	try:
		dom = minidom.parse(xmlFile)
		elements = dom.getElementsByTagName('attr')
		if len(elements) != 0:
			for i in range(0,len(elements)):
				attrId = elements[i].attributes["id"].value
				attrValue = elements[i].childNodes[0].nodeValue
				attrs[attrId] = attrValue
				flagA=True
		else:
			print 'xxx This lattice dont contain any attribue'
		elements = dom.getElementsByTagName('obj')
		if len(elements) != 0:
			for i in range(0,len(elements)):
				objId = elements[i].attributes["id"].value
				objValue = elements[i].childNodes[0].nodeValue
				objs[objId] = objValue
				flagO=True
		else:
			print 'xxx This lattice dont contain any object'
		if flagA and flagO:
			return attrs,objs
	except:
		print 'xxx El fichero no existe o está mal formado.'
		print 'xxx Path del fichero: ' + xmlFile
		print 'xxx Etiqueta sobre la que se realizó la búsqueda: ' + xmlTag
		

		
